<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


function getSkillId($skill,$conn){
    $query = "SELECT id FROM master_skill WHERE SKILL_NAME='$skill'";
    $rs = mysqli_query($conn,$query);
    $id = "";
    while($row = mysqli_fetch_array($rs)){
		$id= $row['id'];
                break;
    }
    return $id;
}
function getSkillMatched($skillId,$conn,$page){
    $total = 10;
    $page=intval($page);
    if($page<=0){
        $offset=$page;
    }else{
        $offset=$page*$total;
    }
    $query = "SELECT skills.id, skills.YEARS_EXP,skills.COMMENTS,skills.SKILL_RATING,user_login.USER_ID FROM skills INNER JOIN "
            . "user_login ON skills.USER_LOGIN_ID=user_login.MYSQL_USER_ID "
            . "WHERE skills.SKILL_ID=$skillId AND skills.TOTEACH='Y' ORDER BY skills.SKILL_RATING DESC LIMIT $total OFFSET $offset";
    return $rs = mysqli_query($conn,$query);
}

function getTotalCountForTable($tableName,$conn){
    $query = "SELECT COUNT(*) AS total FROM $tableName";
    $rs = mysqli_query($conn,$query);
    while($row = mysqli_fetch_array($rs)){
	return $row['total'];
    }
}
function getSkillMatchedCount($skillId,$conn){
    $query = "SELECT COUNT(*) AS total FROM skills INNER JOIN "
            . "user_login ON skills.USER_LOGIN_ID=user_login.MYSQL_USER_ID "
            . "WHERE skills.SKILL_ID=$skillId AND skills.TOTEACH='Y'";
        $rs = mysqli_query($conn,$query);

    while($row = mysqli_fetch_array($rs)){
	return $row['total'];     
    }
}
